import { ElMessage, ElMessageBox } from 'element-plus';

/**
 * 成功的消息
 * @param msg
 */
export const success = (msg: string) => {
  ElMessage.success(msg);
};

/**
 * 失败的消息
 * @param msg
 */
export const error = (msg: string) => {
  ElMessage.error(msg);
};

/**
 * 确认消息
 * @param type
 * @param typeTxt
 * @param content
 */
export const confirm = async (
  type: 'warning' | 'success' | 'error',
  typeTxt: string,
  content: string,
) => {
  try {
    // 确定是否要删除
    const res = await ElMessageBox.confirm(content, typeTxt, {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type,
    });
    if (res === 'confirm') {
      return true;
    }
  } catch (e) {
    return false;
  }
};

/**
 * 展示个人简介
 * @param description
 */

export const showDescription = (description: string) => {
  ElMessageBox.alert(description, {
    title: '个人简介',
  });
};

/**
 * 保存登录状态
 * @param isLogin
 */

export const saveLogin = (isLogin: string) => {
  sessionStorage.setItem('login', isLogin);
};

/**
 * 获取登录状态
 */

export const isLogin = (): boolean => {
  return sessionStorage.getItem('login') === 'true' ? true : false;
};
